﻿namespace ProxyViewModel.Messaging {
	/// <summary>
	/// ProxyViewModel messanging
	/// </summary>
	public class Messaging {
		/// <summary>
		/// Registers a object as a listener to messages.
		/// Object type will be inspected on potential methods that can be considered as message recievers.
		///	 1) Methods that are marked with MessageRecieverAttribute.
		///	 2) Methods that has OnViewModelMessageRecieved name.
		/// </summary>
		/// <param name="viewModel"></param>
		public static void RegisterListener(object viewModel) {
			MessengerManager.RegisterViewModel(viewModel);
		}

		/// <summary>
		/// Publishes a message to the listeners
		/// </summary>
		/// <param name="selector">Selector that is applied on listeners</param>
		/// <param name="parameters">Message paramaeters</param>
		public static void Publish(string selector, object[] parameters) {
			MessengerManager.PublishMessage(selector, parameters);
		}

		/// <summary>
		/// Publishes a message to the listeners
		/// </summary>
		/// <param name="parameters">Message parameters</param>
		public static void Publish(params object[] parameters) {
			MessengerManager.PublishMessage(string.Empty, parameters);
		}
	}
}
